package org.jason.user.service.impl;

import org.jason.model.common.enums.RoleEnum;
import org.jason.model.user.pojos.CuUser;
import org.jason.model.user.pojos.CuUserRole;
import org.jason.user.mapper.CuUserRoleMapper;
import org.jason.user.service.ICuUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户-角色表 服务实现类
 * </p>
 *
 * @author jason
 * @since 2023-07-21
 */
@Service
public class CuUserRoleServiceImpl extends ServiceImpl<CuUserRoleMapper, CuUserRole> implements ICuUserRoleService {

    /**
     * @param user 用户
     * @param role 角色id:使用RoleEnum
     * @return 是否绑定成功
     */
    @Override
    public boolean bindUserRole(CuUser user, RoleEnum role) {
        if(user.getId()==null||user.getUsername()==null){
            return false;
        }
        return this.save(new CuUserRole()
                .setUserId(user.getId())
                .setRoleId(role.getRoleId())
                .setUsername(user.getUsername())
                .setRoleName(role.getRoleName())
        );
    }
}
